import Vue from 'vue'
// import './plugins/axios'
import App from './App.vue'
import router from './router'
import store from './store'
import './plugins/element.js'

Vue.config.productionTip = false

import axios from './http'
Vue.prototype.$axios = axios

router.beforeEach((to, from, next) => {
  // 1 从本地获取 token
  let token = localStorage.getItem('token');
  if (token) {
    // 2 如果用户信息存在则往下执行
    next()
  } else {
    //如果用户 token 不存在则跳转到login页面
    if (to.path === '/') {
      next()
    } else {
      next('/')
    }
  }

})

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
